<!--
 * @Author: xiaxia
 * @Description: 
 * @Date: 2022-10-21 16:17:41
 * @LastEditTime: 2022-11-04 11:39:49
 * @FilePath: \test-demo\src\components\JS\JsArr.vue
-->
<template>
  <div>
    <el-card>
      <el-table
        ref="multipleTable"
        id="third-table"
        :data="tableThird"
        sum-text="总计"
        show-summary
        style="width: 100%"
      >
        <el-table-column prop="sl" label="税率">
        </el-table-column>
        <el-table-column label="抵扣" align="center">
          <el-table-column prop="count1" label="份数" align="center">
          </el-table-column>
          <el-table-column prop="stje1" label="金额" align="center">
          </el-table-column>
          <el-table-column prop="stse1" label="税额" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column label="不抵扣" align="center">
          <el-table-column prop="count2" label="份数" align="center">
          </el-table-column>
          <el-table-column prop="stje2" label="金额" align="center">
          </el-table-column>
          <el-table-column prop="stse2" label="税额" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column label="代办退税勾选" align="center">
          <el-table-column prop="count3" label="份数" align="center">
          </el-table-column>
          <el-table-column prop="stje3" label="金额" align="center">
          </el-table-column>
          <el-table-column prop="stse3" label="税额" align="center">
          </el-table-column>
        </el-table-column>
        <el-table-column label="自营退税勾选" align="center">
          <el-table-column prop="count4" label="份数" align="center">
          </el-table-column>
          <el-table-column prop="stje4" label="金额" align="center">
          </el-table-column>
          <el-table-column prop="stse4" label="税额" align="center">
          </el-table-column>
        </el-table-column>
      </el-table>
      <el-button @click="getTable">获取表格</el-button>
    </el-card>
    </div>
</template>

<script>
export default {
  data() {
    return {
      tableThird: []
    }
  },
  created() {
    this.rateStat()
  },
  methods: {
    async rateStat() {
      // 测试模拟的数据
      let res = [
        {
          deductType: '1', // 1抵扣 2不抵扣 3退税 4代办退税
          stse: 6824.91, // 税额
          count: 1,  // 份数
          sl: '3%', // 税率
          stje: 52499.33 // 不含税金额
        },
        {
          deductType: '2', // 1抵扣 2不抵扣 3退税 4代办退税
          stse: 111.1, // 税额
          count: 1,  // 份数
          sl: '3%', // 税率
          stje: 524.33 // 不含税金额
        },
        {
          deductType: '3', // 3退税
          stse: 130,
          count: 2,
          sl: '10%',
          stje: 1000
        },
        {
          deductType: '1', // 1抵扣
          stse: 112,
          count: 1,
          sl: '10%',
          stje: 100
        },
        {
          deductType: '4', // 1抵扣
          stse: 44,
          count: 4,
          sl: '6%',
          stje: 144
        }
      ]
      let res1 = []
      res.map(item => {
        if(res1.length == 0) {
          if(item.deductType == 1){
            res1.push({sl: item.sl, count1: item.count, stje1: item.stje, stse1: item.stse })
          } else if(item.deductType == 2){
            res1.push({sl: item.sl, count2: item.count, stje2: item.stje, stse2: item.stse })
          } else if(item.deductType == 3){
            res1.push({sl: item.sl, count3: item.count, stje3: item.stje, stse3: item.stse })
          } else if(item.deductType == 4){
            res1.push({sl: item.sl, count4: item.count, stje4: item.stje, stse4: item.stse })
          }
        } else {
          let a = res1.some(it => { // 这里的it是对象
            if(it.sl == item.sl){ // 相同税率
              if(item.deductType == 1){
                it.count1 = item.count
                it.stje1 = item.stje
                it.stse1 = item.stse
              } else if(item.deductType == 2){
                it.count2 = item.count
                it.stje2 = item.stje
                it.stse2 = item.stse
              } else if(item.deductType == 3){
                it.count3 = item.count
                it.stje3 = item.stje
                it.stse3 = item.stse
              } else if(item.deductType == 4){
                it.count4 = item.count
                it.stje4 = item.stje
                it.stse4 = item.stse
              }
              return true
            }
          })
          if(!a) { // 不同税率
            if(item.deductType == 1){
              res1.push({sl: item.sl, count1: item.count, stje1: item.stje, stse1: item.stse })
            } else if(item.deductType == 2){
              res1.push({sl: item.sl, count2: item.count, stje2: item.stje, stse2: item.stse })
            } else if(item.deductType == 3){
              res1.push({sl: item.sl, count3: item.count, stje3: item.stje, stse3: item.stse })
            } else if(item.deductType == 4){
              res1.push({sl: item.sl, count4: item.count, stje4: item.stje, stse4: item.stse })
            }
          }
        }
      })
      this.tableThird = res1
    },
    getTable() {
      console.log('无type', this.$refs.multipleTable)
    }
  }
}
</script>

<style>
</style>